home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5454 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ Gurus! Is it correct?
  5. Date: Mon, 05 Feb 1996 00:33:01 GMT
  6. Organization: Netcom
  7. Message-ID: <31154f3e.254843520@nntp.ix.netcom.com>
  8. References: <4eqvtg$cg5@israel-info.datasrv.co.il> <4etnju$6gn@rolaids.frco.com> <4f0n8s$a3b@news2.ios.com> <311403bf.169980736@nntp.ix.netcom.com> <4f2koo$q5a@news2.ios.com>
  9. NNTP-Posting-Host: ix-dc9-06.ix.netcom.com
  10. X-NETCOM-Date: Sun Feb 04  4:32:21 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. vlad@gramercy.ios.com (Vlastimil Adamovsky) wrote:
  14.  
  15. > miker3@ix.netcom.com (Mike Rubenstein) wrote:
  16. > >vlad@gramercy.ios.com (Vlastimil Adamovsky) wrote:
  17. > >> I don't think the virtual destructor is necessary in this specific
  18. > >> case where you have no added data in subclasses. 
  19. > >Why do you think having data has anything to do with it?  From draft
  20. > >5.3.5:
  21. > >    In the first alternative (delete object), if the static type
  22. > >    of the operand is different from its dynamic type, the static
  23. > >    type shall be a base  class of the operand's dynamic type
  24. > >    and the static type shall have a virtual destructor or the
  25. > >    behavior is undefined.
  26. > I prefer slightly more simple explanation as follows:
  27. >   (The Design and Evolution of C++, chapter 10.5 page 216)
  28. >    ....
  29. >     Had a virtual destructor not been used, the cleanup specified in
  30. > Y's (in our case class B) destructor would not have been performed.
  31. > Here you see you have choice to use virtual destructor or not. 
  32.  
  33. But you don't have a choice.  
  34.  
  35. Or rather, you have a choice of writing a correct program or one that
  36. might do anything since it invokes undefined behavior.
  37.  
  38. Your quote from D&E explains the reasoning and, no doubt, is correct
  39. on many if not most compilers, but the draft has changed the rules a
  40. bit.  In particular, it is not guaranteed that the cleanup in B's
  41. destructor will not be performed.  Nor is it guaranteed that any
  42. destructor will be called.  Nothing is guaranteed, since the behavior
  43. is undefined.
  44.  
  45.  
  46. Michael M Rubenstein
  47.